﻿
namespace FacebookXmpp.Parse
{
	internal class XmlElementDefinition : XmlParseState
    {
        public XmlElementDefinition(XmlParseState from)
            : base(from)
        { }

        public override XmlParseState Parse(StringParser parser)
        {
            parser.SkipWhiteSpace();

            if (parser.PauseIfNearEnd(1))
                return this;

            // Close single XML element
			if (parser.IsNext( "/>" ))
				return new XmlCloseElement( this );

            // XML element which contains data
            if (parser.IsNext(">"))
            {
                parser.Consume(">");
                return new XmlElementInner(this);
            }

            // there is no equals after "name = "...
            if (!parser.Contains('='))
            {
                parser.Pause();
                return this;
            }

            string key = parser.ConsumeTo('=', true);
            parser.Consume("=");
            parser.SkipWhiteSpace();

            return new XmlAttributeValue(this, key);
        }
    }

}